package com.yike.order.service.impl;

import com.yike.order.entity.RefundDetail;
import com.yike.order.mapper.RefundDetailMapper;
import com.yike.order.service.RefundDetailService;
import com.yike.order.param.RefundDetailPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yike.common.base.BaseServiceImpl;
import com.yike.common.pagination.Paging;
import com.yike.common.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 订单退款详情表 服务实现类
 *
 * @author Sakura
 * @since 2024-09-04
 */
@Slf4j
@Service
public class RefundDetailServiceImpl extends BaseServiceImpl<RefundDetailMapper, RefundDetail> implements RefundDetailService {

    @Autowired
    private RefundDetailMapper refundDetailMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveRefundDetail(RefundDetail refundDetail) throws Exception {
        return super.save(refundDetail);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateRefundDetail(RefundDetail refundDetail) throws Exception {
        return super.updateById(refundDetail);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteRefundDetail(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<RefundDetail> getRefundDetailPageList(RefundDetailPageParam refundDetailPageParam) throws Exception {
        Page<RefundDetail> page = new PageInfo<>(refundDetailPageParam, OrderItem.desc(getLambdaColumn(RefundDetail::getCreateTime)));
        LambdaQueryWrapper<RefundDetail> wrapper = new LambdaQueryWrapper<>();
        IPage<RefundDetail> iPage = refundDetailMapper.selectPage(page, wrapper);
        return new Paging<RefundDetail>(iPage);
    }

}
